package com.ego.product.po;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.math.BigDecimal;
import java.io.Serializable;
import java.util.Date;

import com.ego.common.constant.ProductConstant;
import com.ego.product.vo.spu.SpuInfoVo;
import com.ego.product.vo.spu.SpuSaveVo;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @program: ego
 * @description spu信息
 * @author KamTang
 * @date 2022-11-13 12:56:14
 */
@Data
@TableName("pms_spu_info")
@Accessors(chain = true)
public class SpuInfo implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 商品id
	 */
	@TableId
	private Long id;
	/**
	 * 商品名称
	 */
	private String spuName;
	/**
	 * 商品描述
	 */
	private String spuDescription;
	/**
	 * 所属分类id
	 */
	private Long categoryId;
	/**
	 * 品牌id
	 */
	private Long brandId;
	/**
	 *
	 */
	private BigDecimal weight;
	/**
	 * 上架状态[0 - 下架，1 - 上架]
	 */
	private Integer publishStatus;
	/**
	 *
	 */
	private Date createTime;
	/**
	 *
	 */
	private Date updateTime;

	public static SpuInfo fromVo(SpuSaveVo vo) {
		return BeanUtil.copyProperties(vo, SpuInfo.class);
	}

	public SpuInfoVo toVo() {
		return BeanUtil.copyProperties(this, SpuInfoVo.class);
	}

	public void onSale(Long spuId) {
		this.setId(spuId);
		this.setPublishStatus(ProductConstant.StatusEnum.ON_SALE_SPU.getCode());
		this.setUpdateTime(new Date());
	}
}
